<template>
	<view >
		<u-popup :show="addAddressShow" closeable @close="addAddressShow = false">
			<view class="content-box padlr24 padtb40 pad-b185 ctt" >
				<view class="block-tit f-s36 txt-center">
					新增地址
				</view>
				<u--form
					labelPosition="left"
					:model="addressForm"
					:rules="rules"
					ref="uForm"
					labelWidth="160rpx"
				>
					<u-form-item
						label="收货地址："
						prop="address"
						borderBottom
					>
						<view class="w_100 flex-a ju-bt">
							<u-input
								v-model="addressForm.address"
								border="none"
								readonly
								placeholder="点击选择收货地址"
							>
								<view class="" slot="prefix">
									<u--image
										:showLoading="true" 
										:src="getImg('location-icon')" 
										width="40rpx"
										height="40rpx"
									></u--image>
								</view>
							</u-input>
							<u--image
								:showLoading="true" 
								:src="getImg('arrow-right')" 
								width="16rpx"
								height="24rpx"
							></u--image>
						</view>
					</u-form-item>
					<u-form-item
						label="门牌号："
						prop="houseNum"
						borderBottom
					>
						<u--input
							v-model="addressForm.houseNum"
							border="none"
							placeholder="请输入门牌号"
						></u--input>
					</u-form-item>
					<u-form-item
						label="联系人："
						prop="name"
						borderBottom
					>
						<u-input
							v-model="addressForm.name"
							border="none"
							placeholder="请填写收货人的姓名"
						>
							<view class="" slot="suffix">
								<u-radio-group
									v-model="addressForm.addressFormSex"
									activeColor="#FF7171"
									size="36rpx"
								>
									<u-radio
									  label="先生"
									  :name="1"
									  labelSize="28rpx"
									>
									</u-radio>
									<u-radio
									  label="女士"
									  :name="0"
									  labelSize="28rpx"
									  :customStyle="{marginLeft: '32rpx'}"
									>
									</u-radio>
								</u-radio-group>
							</view>
						</u-input>
					</u-form-item>
					<u-form-item
						label="联系电话："
						prop="mobile"
						borderBottom
					>
						<u--input
							v-model="addressForm.mobile"
							border="none"
							placeholder="请填写收货人的手机号码"
						></u--input>
					</u-form-item>
				</u--form>
			</view>
			<view class="fot-box flex-center pad-t40">
				<view class="fot-btn" @click="submit">
					新增地址
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name: "", // 新增地址
		data() {
			return {
				addAddressShow: false,
				rules: {
					// 字段名称
					address: [
						{
							required: true, 
							message: '请选择地址',
							trigger: ['change','blur'],
						},
					],
					houseNum: [
						{
							required: true, 
							message: '请输入门牌号',
							trigger: ['change','blur'],
						},
					],
					name: [
						{
							required: true, 
							message: '请填写收货人的姓名',
							trigger: ['change','blur'],
						},
					],
					mobile: [
						{
							required: true, 
							message: '请填写收货人的手机号码',
							trigger: ['change','blur'],
						},
					],
				},
				addressForm: {
					address: "",
					houseNum: "",
					name: "",
					mobile: "",
					addressFormSex: 1,
				},
			}
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
		methods: {
			submit() {
				this.$refs.uForm.validate().then(res => {
					uni.$u.toast('校验通过')
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ctt{
		background-color: #FFFFFF !important;
		background: #FFFFFF;
	}
	.fot-box {
		.fot-btn {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
			width: 512rpx;
			height: 80rpx;
			background: #FF7171;
			border-radius: 16rpx;
		}
	}
</style>